//
//  ViewController.m
//  录制视频Demo
//
//  Created by longsheng on 2018/6/1.
//  Copyright © 2018年 sjj. All rights reserved.
//

#import "ViewController.h"
#import "SJUserFaceSignRecordVideoVc.h"
#import <AVKit/AVKit.h>
#import <AVFoundation/AVFoundation.h>
@interface ViewController ()<MovieToImageHandlerDeleggate>
@property (weak, nonatomic) IBOutlet UIImageView *movieToImageView;

@end

@implementation ViewController

#pragma mark - 开始录制视频
- (IBAction)startVideoClick:(UIButton *)sender {
    SJUserFaceSignRecordVideoVc *vc=[[SJUserFaceSignRecordVideoVc alloc]init];
    vc.delegate=self;
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - 获取视频第一帧的图片和地址<MovieToImageHandlerDeleggate>
-(void)getMovieToImageHandler:(UIImage *)image videoFilePath:(NSString *)fileResultPath{
    self.movieToImageView.image=image;
    //测试转码的mp4视频是否可播放
    if(fileResultPath.length){
        NSURL *fileURL =[NSURL URLWithString:fileResultPath];
        [self play:fileURL];
        NSData *videoMP4Data = [NSData dataWithContentsOfURL:fileURL];
        //NSLog(@"videoData == %@",videoData);
        CGFloat imgSize=[videoMP4Data length]/1000.0;
        NSLog(@"MP4URL == %@,MP4视频文件大小 == %fM",fileResultPath,imgSize/1000.0);
    }
}
#pragma mark - 播放视频
-(void)play:(NSURL *)videoUrl{
    AVPlayerViewController *playerVc = [[AVPlayerViewController alloc] init];
    AVPlayer *player = [AVPlayer playerWithURL:videoUrl];
    playerVc.player = player;
    [self presentViewController:playerVc animated:YES completion:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"录制视频";
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden=NO;
}

@end
